package hihocoder;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class 风格不统一如何写程序 {

	/**
	 * 驼峰法转snake，碰到大写，则加上_和小写
	 * @param string
	 * @return
	 */
	private static String camel2Snake(String string) {
		StringBuilder sBuilder=new StringBuilder();
		for (int i = 0; i < string.length(); i++) {
			if(Character.isUpperCase(string.charAt(i))){
				sBuilder.append("_");
				sBuilder.append(Character.toLowerCase(string.charAt(i)));
			}else {
				sBuilder.append(string.charAt(i));
			}
		}
		return sBuilder.toString();
	}
	
	private static String snake2camel(String inp) {
		StringBuilder sBuilder=new StringBuilder();
		for (int i = 0; i < inp.length(); i++) {
			if(inp.charAt(i)=='_'){
				i++;
				sBuilder.append(Character.toUpperCase(inp.charAt(i)));
			}else {
				sBuilder.append(inp.charAt(i));
			}
		}
		return sBuilder.toString();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int N=scanner.nextInt();
		scanner.nextLine();
		while (N-->0) {
			String string=scanner.nextLine();
			if(string.indexOf('_')==-1){//驼峰法
				System.out.println(camel2Snake(string));
			}else {
				System.out.println(snake2camel(string));
			}
		}
	}

}
